﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;



[ExecuteInEditMode]
public class LocalizationText : MonoBehaviour {

    public string key = "";

    Text m_Text;

    TMPro.TextMeshProUGUI m_TMText;

    // Use this for initialization
    void OnEnable()
    {
        if (!string.IsNullOrEmpty(key))
        {
            if (Localization.instance != null)
            {
                var str = Localization.instance.GetValue(key/*, out bool get*/);

                //if (get)
                {
                    if (m_Text == null)
                        m_Text = GetComponent<Text>();

                    if (m_Text)
                    {
                        m_Text.text = str;
                        return;
                    }

                    if (m_TMText == null)
                        m_TMText = GetComponent<TMPro.TextMeshProUGUI>();

                    if (m_TMText)
                        m_TMText.text = str;
                }
               /* else
                {

                }*/
            }
        }
    }



	
	// Update is called once per frame
	void Update () {
		
	}
}
